package com.liufanying.sikulix.view;

import com.liufanying.sikulix.Application;
import org.sikuli.script.Pattern;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述
 *
 * @author liufanying
 * @date 2023/5/12 11:16
 */
public class ImageView {

    /**
     * 所有的商品列表
     */
    public static List<Pattern> GOODS_LIST = new ArrayList<>();

    public ImageView() {
        System.out.println("开始初始化所有物品匹配对象");
        File file = new File("D:\\img");
        File[] goodsFiles = new File[0];
        if (file.isDirectory()) {
            goodsFiles = file.listFiles();
        }
        System.out.printf("获取到%d张图片%n", goodsFiles != null ? goodsFiles.length : 0);
        System.out.println("开始实例化物品对象");
        if(goodsFiles != null) {
            for (File goodsFile : goodsFiles) {
                try {
                    Pattern pattern = new Pattern(goodsFile.getAbsolutePath());
                    GOODS_LIST.add(pattern);
                } catch (Exception e) {
                    System.out.printf("实例化失败%s%n", goodsFile.getAbsolutePath());
                }

            }
        }
        System.out.printf("实例化%d个物品对象%n", GOODS_LIST.size());
    }


    public  List<Pattern> getGoodsList(){
        return GOODS_LIST;
    }

}
